#!/usr/bin/perl

require "quotamin-lib.pl";

my (@list, $i, $mykey, $lablename, @df_list, $j, @line, @kmgstr, $table_length);
my ($trcls, %user, $n, %pdcuser);

&header($text{'index_title'}, "", "index", 0, 1);

@list = &list_filesystems();
@df_list = &get_df_detail();

print "<form name=volumeform action='index.cgi' method=post onsubmit='return onsubmit_form();'>";

print "<table class=mode1 border=0 width=100%>";

print "<tr><td width=80% valign=top>";
print "<div style='valign:top;width:100%;height:300;overflow:auto'>";
print "<table class=mode1 border=0 width=100% celladding=0 cellspacing=0>";

print "<tr class=title1><th align=left>$text{'index_th_name'}</th><th align=left>$text{'index_th_totspace'}</th><th align=left>$text{'index_th_freespace'}</th></tr>";

@list = sort {$a->[1] cmp $b->[1]} @list;

$i = 0;
$table_length = 0;
$j = 0;
while($i < @list)
{
	$mykey = @list[$i];
	$lablename = $mykey->[1];
	if($lablename =~ /^LABEL=(.*)/)
	{
		$lablename = $1;
	}
	$j = 0;
	while($j < @df_list)
	{
		chomp($df_list[$j]);
		@line = split(/\s+/, $df_list[$j]);
		if(($line[5] eq $mykey->[0]) && ($mykey->[5] > 0))
		{
			if($i %2)
			{
				$trcls = "class=mode2";
			}
			else
			{
				$trcls = "class=mode1";
			}
			print "<tr $trcls><td><input name=fsindex type=radio onclick=\'document.forms[0].checkeddir.value=\"$mykey->[0]\"; document.forms[0].checkedlable.value=\"$lablename\"; document.forms[0].checkedmode.value=\"$mykey->[4]\"\' value=\"$i\">$lablename</td><td>";
			@kmgstr = &blocks_to_G_str($line[1]);
			printf "%5.2f%s", $kmgstr[0], $kmgstr[1];
			print "</td><td>";
			@kmgstr = &blocks_to_KMG_str($line[3]);
			printf "%5.2f%s", $kmgstr[0], $kmgstr[1];
			print "</td></tr>\n";
			$table_length++;
			last;
		}
		#print "<tr><td>$lablename</td><td>", $df_list[$j], "</td><td></td></tr>";
		$j++;
		#print "<tr><td>$lablename</td><td></td><td></td></tr>";
	}
	$i++;
}



print "</table>";

print "</div>";

print "</td><td valign=top width=18%>";

print "<table width=100%>";
print "<tr><td><input class=button name=defaultquota type=submit onclick='return on_defaultquota_click($table_length, \"$text{'error_msg_select_empty'}\");' value=\"$text{'index_submit_defaultquota'}\"></td></tr>";
print "<tr><td><input class=button name=listuser type=submit onclick='return on_listuser_click($table_length, \"$text{'error_msg_select_empty'}\");' value=\"$text{'index_submit_listuser'}\"></td></tr>";
print "<tr><td><input class=button name=submit_setwarn type=submit onclick='return on_setwarn_click($table_length, \"$text{'error_msg_select_empty'}\");' value=\"$text{'listuser_submit_setwarn'}\" ></td></tr>";
print "</table>";

print "</td></tr>";

print "</table>";

print "<input name=checkeddir type=hidden value=''>";
print "<input name=checkedlable type=hidden value=''>";
print "<input name=checkedmode type=hidden value=''>";
print "<input name=sortmode type=hidden value='name'>";

print "</form>\n";

print <<EOF;
<script>
function onsubmit_form()
{
        document.forms[0].defaultquota.disabled = true;
        document.forms[0].listuser.disabled = true;
        document.forms[0].submit_setwarn.disabled = true;
}

function on_defaultquota_click(length, error_msg)
{
	var i;
	var find = 0;

	if(length < 2)
	{
		if(length < 1)
		{
			return false;
		}
		else
		{
			if(document.forms[0].fsindex.checked)
			{
				find = 1;
			}
		}
	}
	else
	{
		for(i = 0; i < length; i++)
		{
			if(document.forms[0].fsindex[i].checked)
			{
				find = 1;
			}
		}
	}

	if(find == 0)
	{
		//alert("please select an item");
		alert(error_msg);
		return false;
	}

	document.forms[0].action = "defaultquota.cgi";
}

function on_listuser_click(length, error_msg)
{
	var i;
	var find = 0;

	if(length < 2)
	{
		if(length < 1)
		{
			return false;
		}
		else
		{
			if(document.forms[0].fsindex.checked)
			{
				find = 1;
			}
		}
	}
	else
	{
		for(i = 0; i < length; i++)
		{
			if(document.forms[0].fsindex[i].checked)
			{
				find = 1;
			}
		}
	}

	if(find == 0)
	{
		//alert("please select an item");
		alert(error_msg);
		return false;
	}

	document.forms[0].action = "listuser.cgi";
}

function on_setwarn_click(length, error_msg)
{
	var i;
	var find = 0;

	if(length < 2)
	{
		if(length < 1)
		{
			return false;
		}
		else
		{
			if(document.forms[0].fsindex.checked)
			{
				find = 1;
			}
		}
	}
	else
	{
		for(i = 0; i < length; i++)
		{
			if(document.forms[0].fsindex[i].checked)
			{
				find = 1;
			}
		}
	}

	if(find == 0)
	{
		//alert("please select an item");
		alert(error_msg);
		return false;
	}

	document.forms[0].action = "listuser.cgi";

	document.forms[0].action = "edit_warntime.cgi";
}

</script>
EOF

&footer("/", $text{'index'});
